package com.ego.coupon.controller;

import java.util.Arrays;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ego.coupon.po.Coupon;
import com.ego.coupon.service.CouponService;
import com.ego.common.util.Result;

/**
 * @program: ego
 * @description 优惠券信息控制器
 * @author KamTang
 * @date 2022-11-13 13:17:12
 */
@RestController
@RequestMapping("coupon")
public class CouponController {

    @Autowired
    private CouponService couponService;

    /**
     * 信息
     */
    @GetMapping("/get/{id}")
    public Result get(@PathVariable("id") Long id){
		Coupon coupon = couponService.getById(id);
        return Result.ok().put("coupon", coupon);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public Result save(@RequestBody Coupon coupon){
		couponService.save(coupon);
        return Result.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public Result update(@RequestBody Coupon coupon){
		couponService.updateById(coupon);
        return Result.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody Long[] ids){
		couponService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
